﻿using System.Linq;
using RealEstate.Models;
using System.Collections.Generic;
namespace RealEstate
{
    public partial class PropertyEntities
    {
        private DataClassesDataContext dataContext = new DataClassesDataContext();

        public void Add(Property item)
        {
            dataContext.Properties.InsertOnSubmit(item);
            dataContext.SubmitChanges();
        }

        public void Update(Property item)
        {
            var updateItem = (from c in dataContext.Properties where c.PropertyId == item.PropertyId select c).FirstOrDefault();
            dataContext.SubmitChanges();
        }

        public void Delete(int id)
        {
            var item = (from c in dataContext.Properties where c.PropertyId == id select c).FirstOrDefault();
            dataContext.Properties.DeleteOnSubmit(item);
            dataContext.SubmitChanges();
        }

        public Property GetById(int id)
        {
            var item = (from c in dataContext.Properties where c.PropertyId == id select c).FirstOrDefault();
            return item;
        }

        public List<Property> GetAll()
        {
            return dataContext.Properties.OrderBy(c => c.PropertyId).ToList();
        }
    }
}